package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.SaleOut;
import cn.wolfcode.crm.query.SaleOutQueryObject;
import cn.wolfcode.crm.query.JSONResult;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.service.ISaleOutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("saleOut")
public class  SaleOutController {

    @Autowired
    private ISaleOutService saleOutService;

    //由于dataGrid组件返回必须为json,所以跳转界面就分开
    @RequestMapping("view")
    public String view(){
        return "saleOut";
    }

    //编辑界面需要
    @RequestMapping("list")
    @ResponseBody
    public List<SaleOut> list(){
        return saleOutService.selectAll();
    }

    //页面数据
    @RequestMapping("query")
    @ResponseBody
    public PageResult query(SaleOutQueryObject qo){
        return saleOutService.query(qo);
    }

    //编辑
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(SaleOut dept){
            JSONResult jsonResult = new JSONResult();
            try {
                saleOutService.saveOrUpdate(dept);
            }catch (Exception e){
                e.printStackTrace();
                jsonResult.mark(e.getMessage());
            }
        return jsonResult;
    }

    //修改状态
    @RequestMapping("audit")
    @ResponseBody
    public JSONResult audit(Long id){
        JSONResult result = new JSONResult();
        try {
            saleOutService.audit(id);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

}
